import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, OneToMany } from 'typeorm';
import { Client } from "./client";
import { Order } from "./order";

@Entity()
export class Delivery {
  /**
   * Delivery主键，id，自动增长，也是最通常的查找方案
   * @type {number}
   */
  @PrimaryGeneratedColumn()
  id: number;

  /**
   * 是否已经审核
   * @type {boolean}
   */
  @Column({
    default: false
  })
  reviewed: boolean;

  /**
   * 是否已经付款
   * @type {boolean}
   */
  @Column({
    default: false
  })
  paid: boolean;

  /**
   * 订单数量
   * @type {number}
   */
  @Column("int")
  orderQuantity: number;

  /**
   * 送货单总金额，以厘为单位，1000倍
   * @type {number}
   */
  @Column("int")
  totalAmount: number;

  /**
   * 送货单送货时间格式化 20201214
   * @type {number}
   */
  @Column("int")
  deliveryDate: number;

  /**
   * 送货单号
   * @type {string}
   */
  @Column()
  deliveryNumber: string;

  /**
   * 送货单货币
   * @type {string}
   */
  @Column()
  currency: string;

  /**
   * 送货单审稿人
   * @type {string}
   */
  @Column()
  reviewer: string;

  /**
   * 送货单车牌号
   * @type {string}
   */
  @Column()
  plateNumber: string;

  /**
   * 送货单送货地址
   * @type {string}
   */
  @Column()
  deliveryAddress: string;

  /**
   * 送货单客户联系电话
   * @type {string}
   */
  @Column()
  clientPhone: string;

  /**
   * 客户，这个订单属于哪个客户
   * @type Client
   */
  @ManyToOne(type => Client, client => client.deliveries)
  client: Client;

  /**
   * 送货单订单
   */
  @OneToMany(type => Order, order => order.delivery)
  orders: Order[];
}